package com.ztgf.shopping.api.client.shop;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.shopping.models.bo.shop.ShopCategoryRelationSaveBO;
import com.ztgf.shopping.models.bo.shop.ShopCategoryRelationApiSaveBO;
import com.ztgf.shopping.models.vo.shop.ShopCategoryRelationVO;
import com.ztgf.shopping.models.vo.shop.ShopCategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import com.ztgf.shopping.models.service.shop.IShopCategoryRelationService;
import com.ztgf.shopping.models.bo.shop.ShopCategoryRelationBO;
import com.ztgf.shopping.models.dto.shop.ShopCategoryRelationDTO;

import java.util.List;

/**
 * 店铺分类表控制器
 *
 * @author zhanghualang
 * @Date 2020-05-28 14:42:59
 */

@RestController
@RequestMapping("/api/shopCategoryRelation")
@Slf4j
@Api(value = "ShopCategoryRelationApiController",tags = "店铺分类表Api接口")
public class ShopCategoryRelationApiController {

    @DubboReference
    private IShopCategoryRelationService shopCategoryRelationService;

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<ShopCategoryRelationDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        ShopCategoryRelationDTO dto = shopCategoryRelationService.selectById(id);

        return new Result<>(dto);
    }

    @ApiOperation(value = "店铺分类表列表",notes = "店铺分类表列表")
    @PostMapping("/queryList")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<List<ShopCategoryRelationVO>> queryPageList(@RequestParam("id") Long id){

        List<ShopCategoryRelationVO> vos = shopCategoryRelationService.queryList(id);

        return new Result<>(vos);
    }

    @PostMapping("/getCategoryByShopId")
    @ApiOperation(value = "根据店铺ID查找类目佣金",notes = "根据店铺ID查找类目佣金")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<List<ShopCategoryVO>> getCategoryByShopId(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }

        List<ShopCategoryVO> vos = shopCategoryRelationService.getCategoryByShopId(id);
        return new Result<>(vos);
    }
}
